<template>
  <div class="app-container">
    <div class="app-main">
      <div class="mainName">项目列表</div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="状态" prop="runningState">
          <el-select
            v-model="queryParams.runningState"
            placeholder="请选择"
            filterable
            clearable
          >
            <el-option
              v-for="users in statusList"
              :key="users.value"
              :label="users.label"
              :value="users.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="项目名称" prop="projectName">
          <el-input
            v-model="queryParams.projectName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >查询</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
        <el-form-item style="float: right">
          <el-button type="primary" size="mini" @click="addItem"
            >新增项目</el-button
          >
          <el-button
            type="danger"
            size="mini"
            @click="handleDelete"
            :disabled="!delShow"
            >删除选中</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        :data="assetList"
        border
        stripe
        @selection-change="handleSelectionChange"
        :key="1"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" type="index">
        </el-table-column>

        <el-table-column
          label="项目名称"
          align="center"
          show-overflow-tooltip
          prop="projectName"
          min-width="200"
        />
        <el-table-column
          label="地址"
          align="center"
          show-overflow-tooltip
          prop="detailAddress"
          min-width="200"
        />
        <el-table-column
          label="白蚁防治公司"
          align="center"
          show-overflow-tooltip
          prop="controlName"
          min-width="200"
        />
        <el-table-column label="项目类型" align="center" prop="projectType" />
        <el-table-column
          label="小区物业公司"
          align="center"
          prop="propertyManagementCompany"
          min-width="200"
        />
        <!-- <el-table-column label="项目名称" align="center" prop="projectName" /> -->

        <!-- <el-table-column
          label="地址"
          align="center"
          prop="detailAddress"
          min-width="220"
        /> -->

        <el-table-column label="运行状态" align="center" prop="runningState" />
        <el-table-column
          label="监测点数"
          align="center"
          prop="monitorPointNum"
        />
        <!-- <el-table-column label="" align="center" prop="latLong" /> -->

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="230"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="editdetail(scope.row)"
              >编辑
            </el-button>
            <el-button size="mini" type="text" @click="seedetail(scope.row)"
              >详情
            </el-button>
            <el-button size="mini" type="text" @click="message(scope.row)"
              >短信
            </el-button>
            <el-button
              size="mini"
              type="text"
              style="color: red"
              @click="deleteItem(scope.row)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="pagination-container"
      />
    </div>
    <message
      v-if="messageVisible"
      :show="messageVisible"
      @closeMsg="closeMsg"
      :id="messageId"
    ></message>
    <addMsg
      v-if="addMsgShow"
      :show="addMsgShow"
      :detailForm="submitForm"
      :title="msgTitle"
      @closeMsg="closeAddMsg"
    ></addMsg>
    <!-- 这个不要了 先不删 -->
    <detail
      v-if="detailShow"
      :show="detailShow"
      @closeMsg="closeDetail"
      :myTitle="myTitle"
      :detailDis="detailDis"
      :detailRow="detailRow"
      :id="id"
    ></detail>
  </div>
</template>

<script src="/static/tinymce/langs/zh-Hans.js"></script>
<script>
import {
  getAlarmMsg, // 报警短信查询
  queryProjectData, // 项目列表数据查询
  addProjectData, // 新增项目
  delProjectDataByIds, // 项目删除(单个或批量)
} from "@/api/manage/asset";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import detail from "./components/detail";
import message from "./components/message";
import addMsg from "./components/addMsg";

export default {
  name: "ProjectList",
  dicts: [],
  components: { detail, message, addMsg },
  data() {
    return {
      msgId: "",
      msgTitle: "新增",
      detailDis: false,
      myTitle: "详情",
      delShow: false,
      id: null,
      detailRow: {},
      // 新增的表单
      submitForm: {
        projectName: "",
        projectType: "",
        projectLocation: "",
        street: "",
        detailAddress: "",
        controlId: "",
        latLong: "",
        runningState: "",
      },
      messageVisible: false, // 短信弹窗
      messageId: "",
      addMsgShow: false,
      detailShow: false,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      messageTotal: 0,
      // 资产信息表格数据
      assetList: [],
      messageList: [],
      // 弹出层标题
      title: "",
      // 资产分类树桩选项
      assetClassificationOptions: [],
      // 启用日期时间范围
      daterangeStartDate: [],
      // 部门树桩选项
      deptOptions: [],
      // 项目类型
      typeList: [
        {
          value: "住宅",
          label: "住宅",
        },
        {
          value: "非住宅",
          label: "非住宅",
        },
      ],
      options: [
        {
          value: "1",
          label: "1",
        },
        {
          value: "2",
          label: "2",
        },
      ],
      statusList: [
        {
          value: "运行中",
          label: "运行中",
        },
        {
          value: "停止",
          label: "停止",
        },
      ],
      assets: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        runningState: "",
        projectName: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 导入结果弹出框
      resultVisible: false,
      // 人员下拉
      personnels: [],
      // 部门下拉
      departments: [],
      delItemList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    closeMsg() {
      this.messageVisible = false;
    },
    closeAddMsg(val) {
      this.addMsgShow = false;
      if (val) {
        this.getList();
      }
    },
    closeDetail(val) {
      this.detailShow = false;
      if (val) {
        this.getList();
      }
    },
    handleSelectionChange(val) {
      console.log(val, "00000");
      this.delItemList = val.map((item) => {
        return {
          id: item.projectId,
        };
      });

      if (val.length > 0) {
        this.delShow = true;
      } else {
        this.delShow = false;
      }
    },
    editdetail(row) {
      // 在这里调接口获取详情
      this.submitForm = row;
      this.addMsgShow = true;
      this.msgTitle = "编辑";
      // this.id = row.id;
      // this.detailRow = row;
      // this.myTitle = "编辑";
      // this.detailDis = false;
      // this.detailShow = true;
    },
    seedetail(row) {
      // this.id = row.id;
      // this.myTitle = "详情";
      // this.detailDis = true;
      // this.detailRow = row;
      // this.detailShow = true;
      this.submitForm = row;
      this.addMsgShow = true;
      this.msgTitle = "详情";
      console.log(row, "详情");
    },
    message(row) {
      this.messageVisible = true;
      this.messageId = row.projectId;
    },
    deleteItem(row) {
      console.log(row);
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delProjectDataByIds([row.projectId]);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    getList() {
      this.loading = true;
      queryProjectData(this.queryParams)
        .then((res) => {
          if (res.errorCode == "000000") {
            console.log(res, "sssss");
            this.assetList = res.data.list;
            this.total = res.data.total;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    addItem() {
      console.log("新增");
      this.msgTitle = "新增";
      this.submitForm = {
        projectName: "",
        projectType: "",
        projectLocation: "",
        street: "",
        detailAddress: "",
        controlId: "",
        latLong: "",
        runningState: "",
      };
      this.addMsgShow = true;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      let ids = [];

      this.delItemList.forEach((item) => {
        ids.push(item.id);
      });

      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delProjectDataByIds(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.app-main {
  background-color: #fff;
  // padding: 15px 20px;
  border-radius: 8px;
  .btnGroupLeft {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
  }
  .formBox {
    .left {
      display: inline-block;
      height: 44px;
      line-height: 44px;
      width: 100px;
      padding-right: 15px;
      border-left: 1px solid #e4e4dc;
      border-right: 1px solid #e4e4dc;
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #303133;
      text-align: right;
      vertical-align: top;
    }
    .right {
      display: inline-block;
      width: calc(100% - 100px);
      height: 44px;
      border-right: 1px solid #e4e4dc;
      padding: 6px 15px;
      .el-select {
        width: 340px !important;
      }
      .el-input {
        width: 340px !important;
      }
    }
    .formHead {
      width: 100%;
      height: 44px;
      background-color: #5d6d7f;
      height: 44px;
      line-height: 44px;
      text-align: center;
      font-family: MicrosoftYaHei, MicrosoftYaHei;
      font-weight: bold;
      font-size: 12px;
      color: #ffffff;
    }
    .formWhite {
      width: 100%;
      height: 44px;
      background-color: #fff;
    }
    .area {
      .areaLeft {
        width: 130px !important;
        margin-right: 10px;
      }
      .areaRight {
        width: 200px !important;
      }
    }
    .formGray {
      width: 100%;
      height: 44px;
      background-color: #dbe2e6;
    }
  }
  .mainName {
    font-family:
      PingFangSC,
      PingFang SC;
    font-weight: 500;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    color: #000000;
    border-bottom: 1px solid #dcdfe6;
    margin-bottom: 10px;
  }
  .headerTable {
    background: #5d6d7f;
    height: 48px;
    line-height: 48px;
    text-align: center;
    width: 100%;
    color: #fff;
    font-weight: Bold;
    font-size: 14px;
    font-family:
      Helvetica Neue,
      Helvetica,
      PingFang SC,
      Hiragino Sans GB,
      Microsoft YaHei,
      Arial,
      sans-serif;
    border: 1px solid #e3e3e3;
    border-bottom: 0;
  }
}
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
</style>
